package com.zy.study.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.gargoylesoftware.htmlunit.javascript.host.Element;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.zy.study.pojo.CountryData;
import com.zy.study.pojo.TodayData;


public class MyJsonUtil {
	/**
	 * 根据api得到返回的数据json字符串
	 * @param apiUrl
	 * @return
	 * @throws Exception
	 */
	public static  String getJsonByApi(String apiUrl) throws Exception{
		 try{
	            Client client=Client.create();
	            WebResource webResource =client.resource(apiUrl);
	            ClientResponse response =webResource.header("Accept", "application/xml")
	                    .header("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36")
	                    .accept("application/json").get(ClientResponse.class);
	            int code=response.getStatus();
	            if(code!=200)
	            {
	                return null;
	            }
	            return response.getEntity(String.class);
	        }catch(Exception e){
	            throw new RuntimeException("open url exception: ",e);
	        }

	}	
}
